<template>
<div>
  <div>
  <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
    <el-breadcrumb-item :to="{ path: '/admin/index' }">
      <i class="el-icon-s-promotion"></i>
      管理后台首页
    </el-breadcrumb-item>
    <el-breadcrumb-item :to="{path: '/admin/older/list'}">老人健康信息</el-breadcrumb-item>
    <el-breadcrumb-item>入老人健康信息添加</el-breadcrumb-item>
  </el-breadcrumb>
  <el-divider></el-divider>

    <el-card class="box-card">
      <h1 style="font-size: 25px;margin-bottom: 25px;text-align: center">老人信息添加</h1>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="老人姓名:" prop="name">
          <el-input v-model="ruleForm.name" ></el-input>
        </el-form-item>
        <el-form-item label="联系方式:" prop="name">
          <el-input v-model="ruleForm.phoneNumber"></el-input>
        </el-form-item>
        <el-form-item label="性别:" prop="name">
          <el-input v-model="ruleForm.gender"></el-input>
        </el-form-item>
        <el-form-item label="年龄:" prop="name">
          <el-input v-model="ruleForm.age" ></el-input>
        </el-form-item>

        <el-form-item label="老人生日:" prop="birth">
          <el-date-picker
              v-model="ruleForm.birth"
              type="datetime"
              placeholder="选择日期" >
          </el-date-picker>
        </el-form-item>
          <el-form-item label="身高:" prop="height">
            <el-input v-model="ruleForm.height"></el-input>
          </el-form-item>
          <el-form-item label="体重:" prop="weight">
            <el-input v-model="ruleForm.weight" ></el-input>
          </el-form-item>
          <el-form-item label="血压:" prop="bp">
            <el-input v-model="ruleForm.bp" ></el-input>
          </el-form-item>
          <el-form-item label="血糖:" prop="bg">
            <el-input v-model="ruleForm.bg" ></el-input>
          </el-form-item>
          <el-form-item label="血脂:" prop="bl">
            <el-input v-model="ruleForm.bl"></el-input>
          </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">添加</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        id:"",
        name: '测试名称001',
        gender:'男',
        age:'88',
        phoneNumber:'145789',
        birth:"",
        height: 158,
        weight: 45,
        bp: 74.2,
        bg: 74.3,
        bl: 74.5

      },
      rules: {
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = 'http://localhost:8080/olders/add-new';
      /*    console.log('url = ' + url);
          console.log(this.ruleForm.birth);
          let formData = this.qs.stringify(this.ruleForm);
          console.log('formData = ' + formData);*/

          this.axios
              .create({'headers': {'Authorization': localStorage.getItem('jwt') }})
              .post(url,this.ruleForm).then((response)=>{
            let responseBody = response.data;
            if (responseBody.state == 20000) {
              this.$message({
                message: '添加老人信息成功！',
                type: 'success'
              });
              this.resetForm(formName);
            }else {
              this.$message.error(responseBody.message);
            }
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },

}
</script>

<style>
.box-card{
  width: 80%;
  height: 800px;
  margin: 0 auto;
}
.demo-ruleForm{
  width: 50%;
  margin: 0 auto;
}

.el-input {
  width: 500px;
}
</style>